package xjy.smartcommunity.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
import xjy.smartcommunity.R;
import xjy.smartcommunity.activity.WuYeActivity;
import xjy.smartcommunity.bean.General;
import xjy.smartcommunity.bean.PropertyVo;

import static xjy.smartcommunity.R.array.generals;

/**
 * Created by victorzhang on 2017/8/1.
 */

public class GeneralAdapter extends BaseAdapter {
    private List<General> generalList;

    public GeneralAdapter( List<General> generalList) {
        this.generalList = generalList;
    }
    //得到listView中item的总数
    @Override
    public int getCount() {
        return generalList.size();
    }

    @Override
    public Object getItem(int position) {
        return generalList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    //简单来说就是拿到单行的一个布局，然后根据不同的数值，填充主要的listView的每一个item
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //拿到ListViewItem的布局，转换为View类型的对象
//        View layout = View.inflate(WuYeActivity.this, R.layout.listitem_bao_xiu_info, null);
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.listitem_bao_xiu_info, parent, false);
            new ViewHolder(convertView);
        }
        ViewHolder holder = (ViewHolder) convertView.getTag();
//            holder.tvType.setText(propertyList.get(position).getType());
        holder.imageview.setImageResource(generalList.get(position).getImageSrc());
        holder.baoXiuTypeTv.setText(generalList.get(position).getTextInfo());
        return convertView;
//        //找到显示物业类型的ImageView
//        ImageView ivThumb = (ImageView) layout.findViewById(R.id.imageview);
//        //找到显示物业类型的TextView
//        TextView tvName = (TextView) layout.findViewById(R.id.baoXiuTypeTv);
//        //获取军事中下标是position的物业类型对象
//        General general = generals.get(position);
//        //显示图片
//        ivThumb.setImageResource(general.getImageSrc());
//        //显示内容
//        tvName.setText(general.getTextInfo());
//        return layout;
    }
        class ViewHolder {
            private ImageView imageview;
            //            private TextView tvType;
            private TextView baoXiuTypeTv;

            public ViewHolder(View itemView) {
                imageview = (ImageView) itemView.findViewById(R.id.imageview);
//                tvType = (TextView) itemView.findViewById(R.id.baoXiuTypeTv);
                baoXiuTypeTv = (TextView) itemView.findViewById(R.id.baoXiuTypeTv);
                itemView.setTag(this);
            }
        }
    }
